package k2_oop.p2_inheritAndPolymorphic.demo05;

/**
 * 覆盖、继承 建立一个汽车Auto类，
 * 包括轮胎个数，汽车颜色，车身重量、速度等成员变量
 * 并通过不同的构造方法创建实例
 * 至少要求： 汽车能够加速，减速，停车
 */
public class Auto {

    private int tyreCount;
    private String color;
    private double weight;
    private int speed;

    public Auto(int tyreCount, String color, double weight, int speed) {
        this.tyreCount = tyreCount;
        this.color = color;
        this.weight = weight;
        this.speed = speed;
    }

    /**
     * 实现加速的方法
     * @param speed
     */
    public void speedUp(int speed){
        this.speed+=speed;
        System.out.println("加速成功");
    }

    /**
     * 实现减速的方法
     * @param speed
     */
    public void speedDown(int speed){
        if(this.speed>=speed){
            this.speed-=speed;
        }else{
            this.speed = 0;
        }
        System.out.println("减速成功");
    }

    /**
     * 实现停车的方法
     */
    public void stop(){
        this.speed = 0;
        System.out.println("停车了");
    }

    public int getTyreCount() {
        return tyreCount;
    }

    public void setTyreCount(int tyreCount) {
        this.tyreCount = tyreCount;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }
}
